<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewFee extends JView
{
	function display($tpl = null) {

		global $mainframe, $option;

		// Initialise variables
		$user		= & JFactory::getUser();
		$gid		= $user->get('gid');
		$ownuser	= & Ownservice::getUser();
		$document	= & JFactory::getDocument();
		$params 	= & $mainframe->getParams('com_ownservice');

		//get vars
		$rate_id	= JRequest::getVar('rate_id', 0);
		$type		= JRequest::getVar('type', '');
		
		//add style to document
		$document->addStyleSheet(JURI::base().'/components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'/components/com_ownservice/assets/css/nav.css');

		//Get data form the model
		$model		= $this->getModel();
		$row		= &$this->get('Data');
		$rate		= $model->getExchangeRate($rate_id);
		
		// check if it's an edit action
		if($row->id) {
				$canEdit	= ($gid<25)?Ownservice::checkAccess('fee', 'edit', 'fee', 'all'):1;
				if (!$canEdit) {
					JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
					$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
				}
		} else {
				$canAdd		= ($gid<25)?Ownservice::checkAccess('fee', 'add', 'fee', 'all'):1;
				if (!$canAdd) {
					JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
					$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
				}
		}

		//set page title
		if($row->id) {
			if($type =='fee'){
				$params->set('page_title',	JText::_('OWNSERVICE_EDIT_FEE'));
			} else {
				$params->set('page_title', JText::_('OWNSERVICE_EDIT_DESTINATION_FEE'));
			}
		} else {
			if($type == 'fee'){	
				$params->set('page_title',	JText::_('OWNSERVICE_NEW_FEE'));
			} else {
				$params->set('page_title', JText::_('OWNSERVICE_NEW_DESTINATION_FEE'));
			}
		}
		
		$document->setTitle( $params->get('page_title') );

		$this->assignRef('row', $row);
		$this->assignRef('rate', $rate);
		$this->assignRef('type', $type);
		$this->assignRef('rate_id', $rate_id);
		$this->assignRef('params', $params);
		
		parent::display($tpl);
	}
}
